package cuiyt.juc.unsafe;

import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
/**
 * @author cyt
 * @create 2020-05-01 15:46
 */
public class MapTest {

    public static void main(String[] args) {
        Map<Object, Object> map;
        // map = new HashMap<>();
        //  Exception in thread "11" java.util.ConcurrentModificationException
        // map = Collections.synchronizedMap(new HashMap<>());
        map = new ConcurrentHashMap();
        for (int i = 0; i < 30; i++) {
            new Thread(() -> {
                map.put(UUID.randomUUID().toString().substring(0, 2),
                        UUID.randomUUID().toString().substring(0, 2));

                System.out.println(map);
            }, String.valueOf(i)).start();
        }
    }
}
